/*
 * Copyright 2011-2012 Marcin Blazejewski
 *
 * This file is part of Ground0.
 *
 * Ground0 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ground0 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Ground0. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef WLOADER_H_
#define WLOADER_H_

#include "geometry.hpp"
#include "stuff.hpp"
#include "collision.hpp"
#include <fstream>
#include <map>
#include <vector>
#include <string>

using namespace std;

void          load_model(const char *fname, const char *prefix);
Block*        get_model(const char *name);
void          wloader_destroy();
CollisionModel* get_cm(const char *name);

class ObjFile {
private:
    string                  source_file;
    ifstream                f;
    vector<Vector*>         vertices;
    vector<Vector*>         tex_coords;
    vector<Vector*>         normals;
    /** associated material file */
    string                  matsource;

    /** List of face sets per material */
    vector<vector<Face> >   faces;
    /** List of material names for each face set in faces */
    vector<string>          matnames;

public:
    ObjFile(const char *fname);
    ~ObjFile();
    void parse();
    void                      extract(map<string, Block*> &objbase,
                                    map<string, Material*> &matbase,
                                    const char *name);
};


class MatFile {
private:
    string                  source_file;
    ifstream                f;
    map<string, Material*>  matlib;

public:
    MatFile(const char *fname);
    void parse();

    map<string, Material*> &get_matlib() { return matlib; }
    void copy_matlib(map<string, Material*> &copy_to);
};

#endif
